import { FormConfigItem } from "./type";
import { reactive, watch, toRef } from "vue";

interface ReactiveFormConifg {
  list: FormConfigItem[];
  currentItem: null | FormConfigItem;
}

const reactiveFormConifg = reactive<ReactiveFormConifg>({
  list: [],
  currentItem: null,
});

watch(reactiveFormConifg, (val) => {
  console.log(val, "reactiveFormConifg change ing ------");
});

export function useFormConfigList() {
  return toRef(reactiveFormConifg, "list");
}

export function addFormConfig(config: FormConfigItem) {
  reactiveFormConifg.list.push(config);
}

export function useCurrentConifgItem() {
  return toRef(reactiveFormConifg, "currentItem");
}

export function setCurrentConfigItem(config: FormConfigItem) {
  reactiveFormConifg.currentItem = config;
}
